import type { ConsultType } from '@/enums'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    const Consult = ref<PartialConsult>({})
    //设置问诊类型
    const setType = (type: ConsultType) => {
      Consult.value.type = type
    }
    //设置问诊级别
    const setIllnessType = (type: 0 | 1) => {
      Consult.value.illnessType = type
    }
    // 设置科室
    const setDep = (id: string) => (Consult.value.depId = id)
    // 收集数据,记录病情
    const setIllness = (illness: ConsultIllness) => {
      Consult.value.illnessDesc = illness.illnessDesc
      Consult.value.illnessTime = illness.illnessTime
      Consult.value.consultFlag = illness.consultFlag
      Consult.value.pictures = illness.pictures
    }
    const setPatient = (id: string) => (Consult.value.patientId = id)

    //获取优惠券
    const setCounpon = (id: string) => (Consult.value.couponId = id)
    //清理数据
    const clear = () => {
      return (Consult.value = {})
    }
    return {
      Consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCounpon,
      clear
    }
  },
  { persist: true }
)
